package com.jiyun.service.impl;


import com.alibaba.csp.sentinel.util.StringUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiyun.login.pojo.finance.Receivable;
import com.jiyun.login.pojo.finance.ReceivableVo;
import com.jiyun.mapper.ReceivableMapper;
import com.jiyun.result.Result;
import com.jiyun.service.IReceivableService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-02-12
 */
@Service
@Slf4j
public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, Receivable> implements IReceivableService {

    @Autowired
    private ReceivableMapper receivableMapper;

    @Override
    public void lists() {
        List<Receivable> receivables = receivableMapper.selectList(null);
        System.out.println(receivables);
    }

    @Override
    public Result findAll(ReceivableVo receivableVo) {

        Page<Receivable> caresPage = new Page<>(receivableVo.getPages(), receivableVo.getSize());
        QueryWrapper<Receivable> caresQueryWrapper = new QueryWrapper<>();

        if (!StringUtil.isEmpty(receivableVo.getOrderStatus())){
            caresQueryWrapper.eq("order_status",receivableVo.getOrderStatus());
        }
        //时间
        if (!StringUtil.isEmpty(receivableVo.getFormer())&&!StringUtil.isEmpty(receivableVo.getHoo())){
            caresQueryWrapper.between("sign_time",receivableVo.getFormer(),receivableVo.getHoo());
        }
        Page<Receivable> page=receivableMapper.selectPage(caresPage,caresQueryWrapper);
        return Result.ok(page);
    }

    @Override
    public List<Receivable> selelctOne(String receivableNumber) {
        QueryWrapper<Receivable> qw = new QueryWrapper<>();
        if(!StringUtil.isEmpty(receivableNumber)){
            qw.eq("receivable_number",receivableNumber);
        }
        List<Receivable> receivables = receivableMapper.selectList(qw);
        System.out.println(receivables);
        return receivables;
    }


}
